package com.hns.can.master.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysRoleEntity;
import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.master.service.HomeTransitWholeService;
import com.hns.tool.pub.DateTool;

/**
 * 公交首页controler
 * @author:zhangyu
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/homeTransit")
public class HomeTransitWholeController extends BaseController {

	@Autowired
	private HomeTransitWholeService homeTransitWholeService;//公交首页service
	
	/**
	 * 加载公交首页数据
	 * @param dateType 日期类型
	 * @param lineId	线路id
	 * @param funcType	功能类型
	 * @param idxType	业务类型
	 * @param className	转化类型名称
	 * @return
	 * @throws Exception
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@RequestMapping({"/getOverviewChart","/getInitTotallyStatus","/getSafetyIndexStatus","/getInitSafetyTendencyChart",
		"/getInitEnergyIndex","/getEnergyInfluence","/getEnergyTendencyChart","/getEnergyCarsRanking","/getEnergyStatusRanking",
		"/getLoadMaintenanceData","/getLoadSchedule","/getLoadExamGrid","/getLoadMaintenanceEvent"})
	@ResponseBody
	public Object getHomeData(String dateType, String lineId, String funcType, String idxType, String className) throws Exception {
		Map<String, Object> map = formatParams(dateType, lineId, idxType);
		List<T> list = homeTransitWholeService.getHomeData(map, funcType, className);
		return this.getReturnResult(list);
	}
	
	
	/**
	 * 初始化参数
	 * @param dateType 日期类型
	 * @param lineId 线路id
	 * @param idxType 业务类型
	 * @return
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	private Map<String, Object> formatParams(String dateType, String lineId, String idxType){
		SysUserEntity user = this.getCurrentUser().getUser();
		Map<String, Object> map = new HashMap<String, Object>();
		ArrayList<SysRoleEntity> roleList = new ArrayList<SysRoleEntity>(this.getCurrentUser().getSet_role());
		map.put("dateType", dateType);
		map.put("lineId", lineId);
		map.put("idxType", idxType);
		map.put("corpId", user.getCorpId());
		map.put("userId", user.getId());
		map.put("roleIdList", roleList);
		String dateStr = DateTool.SHORT_DATE_FORMAT.format(new Date());
		map.put("curDate", dateStr);
		return map;
	}
	
	@RequestMapping("/getFullDate")
	@ResponseBody
	public Object getFullDate(String dateType, String yesterday){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dateType", dateType);
		map.put("yesterday", yesterday);
		List<T> list = homeTransitWholeService.getFullDate(map);
		return this.getReturnResult(list);
	}
	
}
